//
//  ViewController.m
//  手势转场动画
//
//  Created by iOS on 16/7/18.
//  Copyright © 2016年 iOS. All rights reserved.
//

#import "ViewController.h"
#import "SencondViewController.h"
#import "TrastionAnimation.h"
#import "MyPercentDrivenInteractiveTransition.h"
@interface ViewController ()<UIViewControllerTransitioningDelegate,UINavigationControllerDelegate>
@property(nonatomic,strong)TrastionAnimation * trastionAnimstion;
@property (nonatomic,strong)MyPercentDrivenInteractiveTransition * myPercentDrivenInteractiveTransition;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"first";
    self.view.backgroundColor = [UIColor yellowColor];
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
    btn.frame = CGRectMake(200, 200, 100, 100);
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    self.navigationController.delegate = self;
    
    MyPercentDrivenInteractiveTransition * mypercent = [[MyPercentDrivenInteractiveTransition alloc]init];
//     SencondViewController * second = [[SencondViewController alloc]init];
//    [mypercent writeFromoViewController:self AndToViewController:second];
    self.myPercentDrivenInteractiveTransition =mypercent;
    // Do any additional setup after loading the view, typically from a nib.
}

- (TrastionAnimation *)trastionAnimstion{
    if (!_trastionAnimstion) {
        _trastionAnimstion = [[TrastionAnimation alloc]init];
    }
    return _trastionAnimstion;
}
- (void)click{
    SencondViewController * second = [[SencondViewController alloc]init];
    
    [self.navigationController pushViewController:second animated:YES];
    second.transitioningDelegate =self;
   // [self presentViewController:second animated:YES completion:nil];
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    self.trastionAnimstion.pushOrPop = YES;
    return self.trastionAnimstion;
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{
    self.trastionAnimstion.pushOrPop = NO;
    return self.trastionAnimstion;
}

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC{
    if (operation == UINavigationControllerOperationPush) {
        self.trastionAnimstion.pushOrPop = YES;
        
        [_myPercentDrivenInteractiveTransition writeFromoViewController:fromVC AndToViewController:toVC];
        return self.trastionAnimstion;
    }else{
        self.trastionAnimstion.pushOrPop = NO;
        return self.trastionAnimstion;
    }
}

-(id<UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController
{
  
    return _myPercentDrivenInteractiveTransition.interactionInProgress ? _myPercentDrivenInteractiveTransition : nil;
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
